package com.jz.community.moduleshoppingguide.neighbor.ui.adapter;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.neighbor.bean.PublishTypeBean;

import java.util.List;


public class PublishTypeAdapter extends BaseQuickAdapter<PublishTypeBean.EmbeddedBean.ContentBean, BaseViewHolder> {

    public PublishTypeAdapter(int layoutResId, @Nullable List<PublishTypeBean.EmbeddedBean.ContentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PublishTypeBean.EmbeddedBean.ContentBean entity) {
        TextView type_tv = helper.getView(R.id.item_publish_tips_tv);
        type_tv.setText(entity.getBlogTypeName());

        boolean isSelect = entity.isSelect();

        if (isSelect) {
            type_tv.setBackgroundResource(R.drawable.border_publish_tips_red_line);
            type_tv.setTextColor(mContext.getResources().getColor(R.color.home_red));
        } else {
            type_tv.setBackgroundResource(R.drawable.border_publish_tips_gray_line);
            type_tv.setTextColor(mContext.getResources().getColor(R.color.font_gary_999));
        }

    }

    public void change(int oldPosition, int position) {
        boolean isSelect = mData.get(position).isSelect();
        if (oldPosition != position) {
            mData.get(oldPosition).setSelect(false);
            mData.get(position).setSelect(true);
        } else {
            if (isSelect) {
                mData.get(position).setSelect(false);
            } else {
                mData.get(position).setSelect(true);
            }
        }

        notifyDataSetChanged();
    }
}
